import React, { Component } from 'react';
import F from '../fetch/';
import Temp from './temp';
import {Link} from 'react-router-dom';
import {connect} from 'react-redux';
//import store from '../store'
//import Items from '../components/Item';
//import '../App.css';{,mapDispatch}
import {mapState,mapDispatch} from '../store/map'
class Home extends Component {
  constructor(props){
    super(props);
    this.state={
      data:[],
      isgetData:false
    };
    /*store.subscribe(()=>{//获取状态
      console.log('update',store.getState())
    })
    store.dispatch({//调用更新状态方法
      type:"ADD_NAME",//方法名
      payload:"jack"//不同状态数据
    })
    store.dispatch({
      type:"ADD_AGE",
      payload:100
    })*/
    //console.log(this.props.history)
    //const token=sessionStorage.token;
    //console.log(token);order,'Authorization':token
    if(this.state.isgetData) F.Index.main(this)
    /*F.Index.login();//登录方法
    <div dangerouslySetInnerHTML={{__html: '<h3>hahhah</h3>'}}></div>*/
  }
  staHandler(){
    this.props.addName('jack')
    this.props.addAge(100)
  }
  render() {
    return (
      <div className="Home">
        <Temp title="首页" isNav>
          <button onClick={this.staHandler.bind(this)}>Set</button>
          <p>{this.props.user.name}</p>
          <p>{this.props.user.age}</p>
          { this.state.data.map((item,index)=>{
              return <p key={index}><Link to={{pathname:`/user/${item._id}`}} >{item.name}/{item.price}</Link></p>
            })
          }
        </Temp>
      </div>
    );
  }
}

export default connect(mapState,mapDispatch)(Home);//
